<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
	<th:block th:include="include :: header('修改商品分类')" />
	<link href="../static/css/upload.css" th:href="@{/css/upload.css}" rel="stylesheet" />
</head>

<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-category-edit" th:object="${category}">
			<input name="categoryId" th:field="*{categoryId}" type="hidden">
			<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label">上级部门：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input class="form-control" type="text" id="treeName" onclick="selectCategoryTree()"
							readonly="true" th:field="*{parentName}">
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商品分类名称：</label>
				<div class="col-sm-8">
					<input name="categoryName" th:field="*{categoryName}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">分类排序：</label>
				<div class="col-sm-8">
					<input name="sort" th:field="*{sort}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">分类图标：</label>
				<div class="col-sm-8">

					<div class="file-list-box">
						<div class="file-div-box">
							<input type="hidden" id="logo" name="logo" th:value="${category.logo}">
							<div class="file-delete" onclick="deleteImage('logo')">
								<i class="fa fa-trash-o" title="删除"></i>
							</div>
							<div class="file-upload-tools" onclick="selectImage('logo')">
								<i class="fa fa-cloud-upload" title="上传"> 上传</i>
							</div>
							<img class="file-responsive" id="logoUrl" name="logoUrl"
								th:src="(${#strings.isEmpty(category.logo)}) ? @{/img/upload.png} : @{${category.logo}}"
								layer-index="0" alt="">
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">分类状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}"
							th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-fileinput-js" />
	<script th:inline="javascript">
		var prefix = ctx + "shop/goods/category";
		$("#form-category-edit").validate({
			focusCleanup: true
		});

		/*分类管理-新增-选择父分类树*/
		function selectCategoryTree() {
			var categoryId = $("#treeId").val();
			var excludeId = $("input[name='categoryId']").val();
			if (categoryId > 0) {
				var options = {
					title: '分类选择',
					width: "380",
					url: prefix + "/selectCategoryTree/" + $("#treeId").val() + "/" + excludeId,
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			} else {
				$.modal.alertError("父分类不能选择");
			}

		}

		function doSubmit(index, layero) {
			var body = $.modal.getChildFrame(index);
			$("#treeId").val(body.find('#treeId').val());
			$("#treeName").val(body.find('#treeName').val());
			$.modal.close(index);
		}

		function selectImage(imageFiled) {
			var options = {
				title: '素材库',
				width: 1500,
				height:850,
				url: ctx + "shop/plugin/material/single",
				callBack: function (index, layero) {
					var url = layero.find("iframe")[0].contentWindow.getSelections();
					if (url != "") {
						$("#" + imageFiled).val(url);
						$("#" + imageFiled + "Url").attr("src", url);
						$.modal.close(index);
					}
				}
			};
			$.modal.openOptions(options);
		}

		function deleteImage(imageFiled) {
			$("#" + imageFiled).val("");
			$("#" + imageFiled + "Url").attr("src", "/img/upload.png");
		}

		function submitHandler() {
			if ($.validate.form()) {
				$.operate.save(prefix + "/edit", $('#form-category-edit').serialize());
			}
		}
	</script>
</body>

</html>